package com.cbs.java.component.database.mysql;

import com.cbs.java.component.database.DefaultDatabase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by brochexu on 9/30/14.
 */
public class MySqlDatabase extends DefaultDatabase {
    private final String Driver = "com.mysql.cj.jdbc.Driver";
    private Connection connection;

    public MySqlDatabase(String host, String port, String username, String password, String database) throws ClassNotFoundException {
        Class.forName(Driver);

        String url = String.format("jdbc:mysql://%s:%s/%s?characterEncoding=utf8&useSSL=false", host, port, database);
        try {
            connection = DriverManager.getConnection(url, username, password);
        } catch (SQLException e) {
            e.printStackTrace(System.err);
        }
    }

    @Override
    protected Connection getConnection() {
        return connection;
    }
}
